////////////////////////////////////////////////////////////////////////////////
/// @file    uart_nvic_init.c
/// @author  AE TEAM
/// @brief   Use interrupts to receive data and send it out.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////

// Define to prevent recursive inclusion
#define _UART_PRINT_NVIC_C_

// Files includes
#include "delay.h"
#include "main.h"
#include "led.h"


////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MM32_Hardware_Abstract_Layer
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup UART_PRINT_NVIC
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup UART_PRINT_NVIC_Exported_Functions
/// @{
extern u8 gRxBuf[gRxLen];
//Received status marker
extern u16 gRxFlag;
s8 gPrintBuf[100];

////////////////////////////////////////////////////////////////////////////////
/// @brief  This function is main entrance.
/// @param  None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
s32 main(void)
{
    u8 t;
    u8 len;
    u16 times = 0;
    DELAY_Init();
    LED_Init();
    UART1_NVIC_Init(115200);
    while(1) {
        if(gRxFlag & 0x8000) {
            //receive data length
            len = gRxFlag & 0x3fff;
            UartSendGroup((u8*)gPrintBuf, sprintf((char*)gPrintBuf, "\r\nSend out Data:\r\n"));
            for(t = 0; t < len; t++) {
                //Waiting for the End
                while((UART1->CSR & UART_IT_TXIEN) == 0);
                UART1->TDR = gRxBuf[t];
            }
            UartSendGroup((u8*)gPrintBuf, sprintf((char*)gPrintBuf, "\r\n\r\n"));
            gRxFlag = 0;
        }
        else {
            times++;
            if(times % 5000 == 0) {
                UartSendGroup((u8*)gPrintBuf, sprintf((char*)gPrintBuf, "\r\nMini Board UART test\r\n"));
            }
            if(times % 200 == 0) UartSendGroup((u8*)gPrintBuf, sprintf((char*)gPrintBuf, "Please input Data, End with Enter\r\n"));
            //Flashing LED, indicating that the system is running
            if(times % 30 == 0)LED1_TOGGLE();
            DELAY_Ms(100);
        }
    }
}

/// @}


/// @}

/// @}
